//
//  SMHProductViewController.swift
//  SMHCommerce
//
//  Created by lvzhao on 2020/1/6.
//  Copyright © 2020 lvzhao. All rights reserved.
//

import UIKit
import WebKit

class SMHProductViewController: LZWebViewController {


    var suggestView :SMHProductSuggestView?
    
    override func viewDidLoad() {
        
        self.webUrl = "https://www.baidu.com"
        self.loadingType = .LZWebLoadingTypeUrl
        
        super.viewDidLoad()
        self.navigationItem.title = "订货展"
        
        setupUI()
        
        // Do any additional setup after loading the view.
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        
        
    }
    //MARK: setupUI
    func setupUI() {
        
        self.suggestView = SMHProductSuggestView.init(viewModel: self.viewModel)
        self.view.addSubview(self.suggestView!)
        
    }
    
    //MARK:-UIScrollViewDelegate
    override func scrollViewDidScroll(_ scrollView: UIScrollView) {
          print("滑动中")
        self.suggestViewShow(isShow: false)

      }
      
      
    override  func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
          print("停止滑动")
        self.suggestViewShow(isShow: true)

      }
    
    //重写父类方法
   override  func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        print("====面加载完成")
        self.suggestViewShow(isShow: true)
    }
    
    
    func suggestViewShow(isShow:Bool) {
        if isShow {
            self.suggestView!.show()
        } else {
            self.suggestView!.hidden()
        }
    }
    
    
    
    lazy var viewModel : SMHProductViewModel = {
        let viewModel = SMHProductViewModel()
        return viewModel
    }()
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
